// StationSocket.cpp : implementation file
//

#include "stdafx.h"
#include "Station.h"
#include "StationSocket.h"
#define USER_SOCKET_RECEIVE WM_USER+52
#define USER_SOCKET_CLOSE     WM_USER+37

// CStationSocket

CStationSocket::CStationSocket()
{
}

CStationSocket::~CStationSocket()
{
}


// CStationSocket member functions

void CStationSocket::OnReceive(int nErrorCode)
{
	// TODO: Add your specialized code here and/or call the base class
	TRACE("OnReceive entered%d.\r\n",this);
	::PostThreadMessage(::GetCurrentThreadId(),USER_SOCKET_RECEIVE,0,(LPARAM)this);
	CSocket::OnReceive(nErrorCode);
}

void CStationSocket::OnClose(int nErrorCode)
{
	// TODO: Add your specialized code here and/or call the base class
	TRACE("on close...\r\n");
	this->Close();
	::PostThreadMessage(::GetCurrentThreadId(),USER_SOCKET_CLOSE,0,(LPARAM)this);
	CSocket::OnClose(nErrorCode);
}

BOOL CStationSocket::OnMessagePending()
{
	// TODO: Add your specialized code here and/or call the base class

	MSG msg;
	if(::PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_NOREMOVE))
	{
		if (msg.wParam == (UINT) m_nTimerID)
		{
			// Remove the message and call CancelBlockingCall.
			::PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE);
			CancelBlockingCall();
			return FALSE;  // No need for idle time processing.
		};
	};

	return CSocket::OnMessagePending();
}

BOOL CStationSocket::SetTimeOut(UINT uTimeOut)
{
	m_nTimerID = SetTimer(NULL,0,uTimeOut,NULL);
    return m_nTimerID;

}
BOOL CStationSocket::KillTimeOut()
{
	 return KillTimer(NULL,m_nTimerID);
}
